#! /bin/bash
last_month_date=$(date -d "-1 month" "+%Y-%m-01")
today=$(date -d "now" "+%Y-%m-%d")
if [[ $1 == "" ]]
then
yesterday=$(date -d "-1 day" "+%Y-%m-%d")
else
yesterday=$1
fi
#clazz表处理
hive -S -e "
set hive.exec.orc.compression.strategy=COMPRESSION;
drop table if exists itcast_dimen.itcast_clazz_update;
CREATE TABLE IF NOT EXISTS itcast_dimen.itcast_clazz_update (
  id int COMMENT 'ems课程id(非自增)',
  create_date_time STRING COMMENT '创建时间',
  update_date_time STRING COMMENT '最后更新时间',
  deleted STRING COMMENT '是否被删除（禁用）',
  itcast_school_id STRING COMMENT 'ems校区ID',
  itcast_school_name STRING COMMENT 'ems校区名称',
  itcast_subject_id STRING COMMENT 'ems学科ID',
  itcast_subject_name STRING COMMENT 'ems学科名称',
  itcast_brand STRING COMMENT 'ems品牌',
  clazz_type_state STRING COMMENT '班级类型状态',
  clazz_type_name STRING COMMENT '班级类型名称',
  teaching_mode STRING COMMENT '授课模式',
  start_time STRING COMMENT '开班时间',
  end_time STRING COMMENT '毕业时间',
  comment STRING COMMENT '备注',
  detail STRING COMMENT '详情(比如：27期)',
  uncertain STRING COMMENT '待定班(0:否,1:是)',
  tenant int COMMENT '租户',
  ends_time STRING COMMENT '有效时间')
comment '班级信息表'
PARTITIONED BY(starts_time STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
stored as orc
TBLPROPERTIES ('orc.compress'='SNAPPY','orc.create.index'='true','orc.bloom.filter.columns'='id');"

sqoop import \
--connect jdbc:mysql://192.168.52.150:3306/scrm \
--username root \
--password 123456 \
--query 'select *,FROM_UNIXTIME(unix_timestamp(),"%Y-%m-%d") as starts_time,date_format("9999-12-31","%Y-%m-%d") as ends_time 
from itcast_clazz 
where (create_date_time>="${yesterday} 00:00:00" and create_date_time<"${today} 00:00:00")
or (update_date_time>="${yesterday} 00:00:00" and update_date_time<"${today} 00:00:00") and $CONDITIONS' \
--hcatalog-database itcast_dimen \
--hcatalog-table itcast_clazz_update \
--hive-partition-key start_time \
--hive-partition-value ${yesterday} \
-m 100 \
--split-by id

#relationship表和线索表的处理可以用之前的脚本